#include <ctime>
#include "randomizer.h"

int Randomizer::generateRandomNumber(gen& genIn, int end)
{
	boost::uniform_int<int> dist(0, end) ;
  	return dist(genIn) ;
}

void Randomizer::operator() (CircuitGraph& graphIn)
{
	
	std::cout << "Start randomizer...." << std::endl;
	
	
	int vn = boost::num_vertices(graphIn) ;
	
	gen generator(42u) ;
	generator.seed (static_cast<unsigned int>(std::time(0))) ;
	
	int gateIndex, cellIndex ;
	
	generator.seed (static_cast<unsigned int>(std::time(0))) ;
	
	while (true)
	{
		if   (graphIn[gateIndex].gateType == Combinational)	
			break ;
		gateIndex = generateRandomNumber(generator, vn-1) ;
	}
		
		
	int numberOfCells = graphIn[gateIndex].listOfCells.size() ;
	
	
	while (true)
	{
		cellIndex = generateRandomNumber(generator, numberOfCells) ;
		if (graphIn[gateIndex].listOfCells[cellIndex] != graphIn[gateIndex].cellName )
			break ;
	}
	
	boost::graph_traits<boostGraph>::vertex_iterator vi, vi_end ;

	
	std::cout << "Gate index: " << gateIndex << std::endl ;
	std::cout << "Number of gates: " << vn << std::endl ;
	std::cout << "Number of cells: " << numberOfCells << std::endl ;
	std::cout << "Generate Random Number..." << std::endl ;
	

	
	std::cout << "Ther random cell index is generated..." << cellIndex << std::endl ;
	
	std::cout << "Gate (instance name, cell name): ( " << graphIn[ gateIndex ].instanceName
				<< ", " << graphIn[ gateIndex ].cellName << ")" << std::endl ;	
	
	graphIn[gateIndex].cellName = graphIn[gateIndex].listOfCells[cellIndex] ;
	
	std::cout << "Gate " << graphIn[gateIndex].instanceName << " is sized to " 
			<< graphIn[gateIndex].cellName << std::endl ;
			
			
	std::cout << "end of randomizer..." << std::endl ;

}

